import axios from '@/api/fetch';
//import * as types from './types';
import SERVER from '@/api/server';


//旧件入库
//旧件入库 - 主页面查询
export const getListByPage = params => axios.post(`${SERVER.CLAIMFAC}/rPReturn/getListByPage`,  params );
//新增的保存
export const newSave = params => axios.post(`${SERVER.CLAIMFAC}/rPReturn/saveOne`,  params );
//批量启动
export const piliangqiyong = data => axios.post(`${SERVER.CLAIMFAC}/rPReturn/updateEnableByIds`,  null ,{params : data} );
//批量停用
export const piliangtingyong = data => axios.post(`${SERVER.CLAIMFAC}/rPReturn/updateEnableByIds`,  null ,{params : data} );
//Excel导出
// export const excelExport = params => axios.get(`${SERVER.CLAIMFAC}/rPReturnWhMp/getListForExport`, params);
// export const excelExport = params => axios.post(`${SERVER.CLAIMFAC}/rPReturnWhMp/getListForExport`,  params );

// 选择旧件列表
export const getDestoryListByPage = params => axios.post(`${SERVER.CLAIMFAC}/rPCmsClaim/getDestoryListByPage`,  params );

export const getReturnListByPage = params => axios.post(`${SERVER.CLAIMFAC}/rPCmsClaim/getReturnListByPage`,  params );

//通过ID查
export const selectById = params => axios.get(`${SERVER.CLAIMFAC}/rPReturn/selectById/${params.id}`);

export const excelExport = params => {
  return axios({
    url:`${SERVER.CLAIMFAC}/rPReturn/getListForExport`,
    method: 'get',
    params: params,
    responseType: 'blob'
  });
};

//一般车辆配件类型保修期编辑弹窗的保存
export const editSave = params => axios.post(`${SERVER.CLAIMFAC}/rPReturn/updateByPtId`,  params );

//签收
export const sign = params => axios.post(`${SERVER.CLAIMFAC}/rPReturn/sign`,  params );
//导出
export const getListForExportNew = (params) => axios.post(`${SERVER.CLAIMFAC}/rPReturn/getPreReturnListForSignExport`, params, {
  responseType: 'blob'
});
//导出
export const getListForExport = params =>
  axios({//用axios发送post请求
    method: 'post',
    url: `${SERVER.CLAIMFAC}/rPReturn/getPreReturnListForSignExport`,//请求地址
    responseType: 'blob',//表明返回服务器返回的数据类型
    headers: {'Content-Type': 'application/json'},
    data: params
  })
    .then(res => {//处理返回的文件流
      const blob = new Blob([res.data]);//newBlob([res])中不加data就会返回下图中[objeceobjece]内容（少取一层）
      if (res.headers['content-disposition']) {
        const fileName = decodeURI(res.headers['content-disposition'].split(';')[1].split('=')[1]); //这里可以自定义名称，发现设置xlsx文件类型下载后打开会提示下面图-1的无效报错,所以我用了xls格式
        const elink = document.createElement('a');
        elink.download = fileName;
        elink.style.display = 'none';
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href);//释放URL对象
        document.body.removeChild(elink);
      }
    })
//下载中心导出
export const exporturl = params => axios.post(`/api/cmscloud.excel/downloadExcel/exportExcel/${params.CODE}`, params);
//批量通过
export const piLiangTongGuo = params => axios.post(`${SERVER.CLAIMFAC}/rPReturn/dealInStockList`, params);

//批量不合格
export const piLiangBuHeGe = params => axios.post(`${SERVER.CLAIMFAC}/rPReturn/batchNoqualified`, params);

//批量驳回
export const piLiangBuoHui = data => axios.post(`${SERVER.CLAIMFAC}/rPReturn/updateEnableByIds`,  null ,{params : data} );


// // 客户订单页查询
// export const getOrders = params => axios.get(`${SERVER.CYXDMS_RETAIL}/ordermanage/customerOrders`, { params });

// // 新增客户订单
// export const addOrders = params => axios.post(`${SERVER.CYXDMS_RETAIL}/ordermanage/customerOrders`, { params });

// // 修改客户订单
// export const modifyOrders = params => axios.put(`${SERVER.CYXDMS_RETAIL}/ordermanage/customerOrders`, { params });

// // 根据id查询客户订单
// export const quyOrders = (id, params) => axios.get(`${SERVER.CYXDMS_RETAIL}/ordermanage/customerOrders/${id}`, { params });

// // 查询车辆列表
// export const quyvehicle = (id, params) => axios.get(`${SERVER.CYXDMS_RETAIL}/ordermanage/customerOrders/${id}/vehicleList`, { params });

// // 删除客户订单(物理删除)
// export const deleteOrders = params => axios.post(`${SERVER.CYXDMS_RETAIL}/ordermanage/customerOrders/delete`, { params });

// // 订单经理审核查询
// export const managerAudit = params => axios.get(`${SERVER.CYXDMS_RETAIL}/ordermanage/customerOrders/manageVerify/query`, { params });

// 删除客户订单(物理删除)
//export const deleteOrders = params => axios.post(`${SERVER.DCSCLOUD_SALES}/ordermanage/customerOrders/delete`, { params });

// 撤回客户订单
//export const withdrawOrders = (id, params) => axios.post(`${SERVER.DCSCLOUD_SALES}/ordermanage/customerOrders/withdraw/${id}`, { params });

// 提交客户订单
//export const subOrders = params => axios.post(`${SERVER.DCSCLOUD_SALES}/ordermanage/customerOrders/submit`, { params });

// 作废客户订单(逻辑删除)
//export const toVOrders = (id, params) => axios.post(`${SERVER.DCSCLOUD_SALES}/ordermanage/customerOrders/nullify/${id}`, { params });





